package com.woniuxy.joylife.manager.controller;

import com.woniuxy.common.constant.RealNameCertificationConstant;
import com.woniuxy.common.constant.UserTypeConstant;
import com.woniuxy.joylife.manager.VO.AuthVO;
import com.woniuxy.joylife.manager.service.ManagerService;
import com.woniuxy.joylife.manager.service.OwnerService;
import com.woniuxy.joylife.manager.service.OwnerUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ManagerAuthenticationController {

    @Autowired
    ManagerService managerService;

    @Autowired
    OwnerService ownerService;

    @Autowired
    OwnerUserService ownerUserService;

    @RequestMapping("/manager/realNameCertification")
    public Integer authenticate(@RequestBody AuthVO authVO){
        // 根绝类型决定校验对象
        Byte authType = authVO.getCenterUsertype();
        if(authType==null){
            return RealNameCertificationConstant.REJECT;
        }
        if(UserTypeConstant.MANAGER_TYPE == authType){
            //校验字段 物业名、物业证书
            if(managerService.checkManager(authVO)){
                return RealNameCertificationConstant.PASS;
            }else {
                return RealNameCertificationConstant.REJECT;
            }
        }else if (UserTypeConstant.ONWER_TYPE == authType){
            // 校验业主
            if(ownerService.checkExist(authVO)){
                return RealNameCertificationConstant.PASS;
            }else {
                return RealNameCertificationConstant.REJECT;
            }
        }else{
            return RealNameCertificationConstant.REJECT;
        }
    }

}
